<template>
  <div class="auditList">
    <section class="header clearfix">
      <span>人员审核</span>
    </section>
    <ul class="menu-swtich clearfix">
      <li
        v-for="(item, index) in menu"
        :key="index"
        :class="[isProcess == index ? 'active' : '']"
        @click="switchFun(index)"
      >
        {{ item.title }}
      </li>
      <el-button
        type="primary"
        :disabled="exportDataLoading"
        :loading="exportDataLoading"
        @click="exportData"
        >导出审核</el-button
      >
      <el-button
        type="primary"
        :disabled="exportEmployeeLoading"
        :loading="exportEmployeeLoading"
        @click="exportEmployee"
        >导出员工</el-button
      >
      <!-- <el-button
        type="primary"
        v-if="inOutJobStatus == 1 || inOutJobStatus == 2"
        :disabled="excelData.length <= 0"
        :loading="outInutLoading"
      >
        导出
        <download-excel
          style="
            position: absolute;
            width: 100%;
            left: 0;
            height: 100%;
            top: 0;
            opacity: 0;
          "
          :data="excelData"
          :name="excelName"
          :before-finish="finishExcel"
        >
        </download-excel>
      </el-button> -->
      <el-button type="success" @click="jumpImportPage">导入</el-button>
    </ul>
    <div class="search-box" @keyup.enter="searchFun">
      <i class="iconfont iconsearch1"></i>
      <el-input
        placeholder="输入身份证进行搜索"
        class="search"
        v-model.trim="idCard"
        clearable
      ></el-input>
    </div>
    <div class="search-box search-box-last">
      <section class="option">
        <span>类别:</span>
        <el-select
          v-model="inOutJobStatus"
          @change="getData"
          placeholder="请选择"
        >
          <el-option
            v-for="item in typeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </section>
      <section class="option">
        <span>参保单位:</span>
        <el-select
          v-model="platformId"
          clearable
          @change="getData"
          placeholder="请选择"
        >
          <el-option
            v-for="item in platformOptions"
            :key="item.platformId"
            :label="item.platformName"
            :value="item.platformId"
          ></el-option>
        </el-select>
      </section>
      <section class="option">
        <span>日期:</span>
        <el-date-picker
          v-model="date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="getData"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </section>
    </div>
    <div class="table">
      <el-table
        ref="multipleTable"
        :data="auditList"
        v-loading="loading"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
        <el-table-column
          prop="platformName"
          fixed
          label="参保单位"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column fixed label="类型">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.auditType == 0">{{
              scope.row.auditType | auditTypeFilter
            }}</el-tag>
            <el-tag type="success" v-else-if="scope.row.auditType == 1">{{
              scope.row.auditType | auditTypeFilter
            }}</el-tag>
            <el-tag type="warning" v-else>{{
              scope.row.auditType | auditTypeFilter
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="fullName"
          fixed
          label="姓名"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          :formatter="sexFormatter"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="手机号"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="idCard"
          label="身份证"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="companyName"
          label="公司名称"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="content"
          label="停缴原因"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="auditStatus"
          label="审核结果"
          :formatter="auditStatusFormatter"
        ></el-table-column>
        <el-table-column
          label="审核不通过原因"
        >
        <template slot-scope="scope">
          {{scope.row.auditStatus=="2"?(scope.row.auditContent && JSON.parse(scope.row.auditContent)[JSON.parse(scope.row.auditContent).length-1].remark):""}}
        </template>

        </el-table-column>
        <el-table-column label="详情" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="look(scope.row.auditId, scope.row.auditType)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  requestApiPost,
  requestApiExportUnCheck,
  requestApiExportUnCheckPerson,
} from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
import JsonExcel from "vue-json-excel";
import base from "../assets/js/base";
export default {
  name: "auditList",
  data() {
    return {
      auditList:[],
      date: [],
      platformId: "",
      excelName: "",
      inOutJobStatus: "0",
      idCard: "",
      isDisabled: true,
      loading: false,
      outInutLoading: false,
      disposeArr: [],
      total: null,
      current: 1,
      isProcess: 0,
      pageSize: 6,
      menu: [
        { title: "未处理", value: "0" },
        { title: "已通过", value: "1" },
        { title: "未通过", value: "2" },
      ],
      //是否入职或离职审核 0无；1入职；2离职
      typeOptions: [
        {
          value: "0",
          label: "全部",
        },
        {
          value: "1",
          label: "新增",
        },
        {
          value: "2",
          label: "停缴",
        },
      ],
      platformOptions: [], //参保单位
      excelData: [],
      exportDataLoading: false,
      exportEmployeeLoading: false,
    };
  },
  methods: {
    //导出结束
    finishExcel() {
      this.outInutLoading = true;
      setTimeout(() => {
        this.outInutLoading = false;
      }, 2000);
    },
    handleCurrentChange(e) {
      this.current = e;
      this.getData();
    },
    handleSizeChange(e) {
      this.pageSize = e;
      this.getData();
    },
    /**接口导出审核列表 */
    exportData() {
      this.exportDataLoading = true;
      var reqData = {};

      let url = requestApiExportUnCheck(reqData);
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link); // 下载完成移除元素
      window.URL.revokeObjectURL(url); // 释放掉blob对象
      this.exportDataLoading = false;
    },

    /**接口导出员工列表 */
    exportEmployee() {
      this.exportEmployeeLoading = true;
      var reqData = {
        // companyId: item.companyId,
        // companyName: item.companyName,
      };

      let url = requestApiExportUnCheckPerson(reqData);
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link); // 下载完成移除元素
      window.URL.revokeObjectURL(url); // 释放掉blob对象
      this.exportEmployeeLoading = false;
    },

    outPutConfirm() {},
    searchFun() {
      this.current = 1;
      this.auditList = [];
      this.getData();
    },
    handleSelectionChange(val) {
      let newArr = JSON.parse(JSON.stringify(val));
      console.log(newArr);
      this.disposeArr = [];
      if (this.inOutJobStatus == "2") {
        //停缴
        this.disposeArr = newArr.map((e, i) => {
          return {
            参保单位: e.platformName,
            姓名: e.fullName,
            证件号码: "'" + e.idCard,
            社保医保停缴原因: e.insuranceStopPayContent,
            社保停缴月份: e.insuranceStopPayMonth,
            医保停缴月份: e.medicalInsuranceStopPayMonth,
            医保申报工资: e.socialSecurityBasic,
            公积金停缴原因: e.fundStopPayContent,
            是否操作社保: e.isPaySocialSecurity == 1 ? "是" : "否",
            是否操作医保: e.isPaySocialSecurity == 1 ? "是" : "否",
            是否操作公积金: e.isPayFund == 1 ? "是" : "否",
          };
        });
        this.excelName = "停缴人员列表";
      } else if (this.inOutJobStatus == "1") {
        //新增
        this.disposeArr = newArr.map((e, i) => {
          return {
            参保单位: e.platformName,
            姓名: e.fullName,
            证件号码: "'" + e.idCard,
            证件类型: "身份证",
            手机号码: e.phone,
            "联系地址(区县)": e.areaName,
            "联系地址(详细地址)": e.address,
            国籍: e.country,
            户口所在地址: e.permanentAddress,
            户籍性质: e.censusRegisterType,
            参保身份: e.insuredStatus,
            职工工种: e.typeOfWork,
            参保月份: e.socialSecurityDate,
            参保申报工资: e.socialSecurityBasic,
            公积金月均工资: e.fundBasic,
            是否操作社保: e.isPaySocialSecurity == 1 ? "是" : "否",
            是否操作医保: e.isPaySocialSecurity == 1 ? "是" : "否",
            是否操作公积金: e.isPayFund == 1 ? "是" : "否",
          };
        });
        this.excelName = "新增人员列表";
      }

      this.excelData = this.disposeArr;
    },
    look(auditId, auditType) {
      this.$router.push({
        path: "/auditDetail",
        query: { auditId, auditType },
      });
    },
    switchFun(i) {
      this.isProcess = i;
      this.current = 1;
      this.getData();
    },
    jumpImportPage() {
      this.$router.push({
        path: "/auditImport",
      });
    },
    //获取数据
    getData() {
      this.loading = true;
      this.auditList = [];

      let submitTimeStart =
        this.date && this.date.length > 0 ? this.date[0] : "";
      let submitTimeEnd = this.date && this.date.length > 0 ? this.date[1] : "";

      var reqData = {
        idCard: this.idCard,
        platformId: this.platformId,
        submitTimeStart,
        submitTimeEnd,
        inOutJobStatus: this.inOutJobStatus,
        isProcess: this.isProcess,
        current: this.current,
        pageSize: this.pageSize,
      };
      base.saveSearchCriteria(this.$route.path, reqData);
      let reqReport = reqRep({ traCode: "_LIST_AUDIT_V2_2", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.auditList = resReport.data.records;
          this.total = parseInt(resReport.data.total);
          // if (this.isProcess == "0") {
          //   this.$store.commit("changeAudit", this.total);
          // }
        }
      });
    },
    //获取参保单位
    getPlatform() {
      var reqData = {
        current: 1,
        pageSize: 999,
      };
      let reqReport = reqRep({ traCode: "_LIST_PAY_PLATFORM", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.platformOptions = resReport.data.records;
          this.getData();
        }
      });
    },
    sexFormatter(a, b, c) {
      if (c == 1) {
        return "男";
      } else if (c == 2) {
        return "女";
      } else {
        return "未知";
      }
    },
    //审核结果 0未审核；1审核通过；2审核不通过
    auditStatusFormatter(a, b, c) {
      if (c == "0") {
        return "未审核";
      } else if (c == "1") {
        return "已通过";
      } else if (c == "2") {
        return "审核不通过";
      }
    },
    valueFormatter(a, b, c) {
      if (c) {
        return c;
      } else {
        return "-";
      }
    },
  },
  filters: {
    //审核类型0入职审核；1离职审核；2停缴公积金审核；3减少缴纳项目；4增加缴纳项目
    auditTypeFilter(c) {
      if (c == 0) {
        return "入职审核";
      } else if (c == 1) {
        return "离职审核";
      } else if (c == 2) {
        return "停缴公积金审核";
      } else if (c == 3) {
        return "减少缴纳项目";
      } else if (c == 4) {
        return "增加缴纳项目";
      } else if (c == 5) {
        return "修改缴纳项目";
      }
    },
  },
  components: {
    downloadExcel: JsonExcel,
  },

  created() {
    //获取路由参数
    if (Object.keys(this.$route.query).length > 0) {
      let query = this.$route.query;
      let that = this;
      for (const key in query) {
        if (Object.hasOwnProperty.call(query, key)) {
          const element = query[key];
          if (key == "pageSize" || key == "current" || key == "platformId") {
            that[key] = base.strToNumber(element);
          } else if (key == "inOutJobStatus") {
            that[key] = String(element);
          } else {
            if (key == "submitTimeStart" || key == "submitTimeEnd") {
              if (key == "submitTimeStart" && element) {
                that.date.splice(0, 1, element);
              }
              if (key == "submitTimeEnd" && element) {
                that.date.splice(1, 1, element);
              }
            } else {
              that[key] = element;
            }
          }
        }
      }
    }
    this.getPlatform();
  },
};
</script>
<style scoped>
.header {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #eee;
}
.header .org {
  float: right;
  cursor: pointer;
}
.org:hover {
  color: #13cb6e;
}
.header i {
  margin-right: 5px;
}
.opt-user {
  padding: 20px 15px;
}
.opt-user > section {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}
.opt-user i {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.opt-user .iconadd1 {
  color: #13cb6e;
}
.opt-user .iconbiaoge-xiazai {
  color: #33ac37;
}
.add-user:hover {
  color: #13cb6e;
}
.input-user:hover {
  color: #33ac37;
}
.menu-swtich {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.menu-swtich li {
  display: inline-block;
  padding: 0 15px;
  cursor: pointer;
}
.menu-swtich .el-button {
  margin-top: 5px;
  float: right;
  margin-right: 10px;
}

.active {
  color: #13cb6e;
  border-bottom: 2px solid #13cb6e;
}
.search-box {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.search-box-last {
  border-top: none;
}
.search-box i {
  margin-left: 15px;
  vertical-align: middle;
}
.search-box .search {
  display: inline-block;
  width: calc(100% - 36px);
}
.search-box .option {
  display: inline-block;
  margin-left: 15px;
}
.search-box .el-select {
  width: 150px;
}
.search-box .el-select input {
  min-width: 100px;
  background-color: #eee;
}
.search-box .batchChange {
  display: inline-block;
  color: #999;
  font-size: 14px;
  cursor: pointer;
}

.showMoney {
  padding: 15px;
}
.showMoney .sm-h {
  margin-bottom: 40px;
}
.sm-h section {
  display: inline-block;
  margin-right: 20px;
}
.sm-h .month {
  margin-left: 10px;
  color: #999;
}
i {
  color: #999;
  font-size: 16px;
}
.download {
  float: right;
  font-size: 14px;
  margin-right: 0 !important;
}
.sm-f > ul {
  display: inline-block;
  width: 100px;
  margin-right: 15px;
  color: #666;
}
.sm-f .value {
  color: #666;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
}
.sm-f .button {
  float: right;
  width: 140px;
  text-align: center;
  height: 50px;
  font-size: 20px;
  line-height: 50px;
  color: #fff;
  border-radius: 4px;
  background-color: #13cb6e;
}
.table {
  margin-top: 4px;
}
.table .content {
  display: inline-block;
  border-right: 1px solid #ccc;
}
.table .content:last-child {
  border: none;
}
.table .content > section {
  padding: 10px 15px;
}
.table .content > section span {
  margin-right: 10px;
  display: inline-block;
  width: 80px;
  color: #999;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.table .content > section span:nth-child(2) {
  text-align: center;
}
.table .content > section span:last-child {
  margin-right: 0;
  text-align: center;
}
.rests {
  float: right;
}
</style>
